3.3-ThisType
Create by fall on 2022-02-25 Recently revised in 2022-02-25
ThisType
type Point = {
x: number;
y: number;
moveBy(dx: number, dy: number): void;
};
let p: Point = {
x: 10,
y: 20,
moveBy(dx, dy) {
this.x += dx; // this has type Point
this.y += dy; // this has type Point
}
};
let foo = {
x: 'hello',
f(n: number) {
this; // { x: string, f(n: number): void }
}
};
let bar = {
x: 'hello',
f(this: { message: string }) {
this; // { message: string }
}
};